import os
file = r'D:/my/壹伴小插件8.0.11/assets'

for root, dirs, files in os.walk(file):
        for file in files:
            try:
                path = os.path.join(root, file)
                print(path)
                lines = open(path,encoding='utf-8').readlines()[0].split(";")
                # 一般压缩后的文件所有代码都在一行里
                # 视情况设定索引，我的情况时第0行是源代码。
                indent = 0
                formatted = []
                for line in lines:
                    newline = []
                    for char in line:
                        newline.append(char)
                        if char == '{':  # { 是缩进的依据
                            indent += 1
                            newline.append("\n")
                            newline.append("\t" * indent)
                        if char == "}":
                            indent -= 1
                            newline.append("\n")
                            newline.append("\t" * indent)
                    formatted.append("\t" * indent + "".join(newline))

                print(";\n".join(formatted))
                open(path, "w").writelines(";\n".join(formatted))
            except Exception as err:
                 1 + 1
                 print(err)


